home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
275_02
/
rijn31.c
< prev
next >
Wrap
Text File
|
1980-01-01
|
28KB
|
947 lines
/* rijn31.c */
/* program for LCA31 option 'd' */
/* display de Bruijn diagram - 1st, 2nd, & 3rd gen */
/* Harold V. McIntosh, 20 February 1988 */
/* 21 February 1988 - add j0=i0; to Pass 4's [HVM] */
/* Copyright (C) 1987 */
/* Copyright (C) 1988 */
/* Harold V. McIntosh */
/* Gerardo Cisneros S. */
# define JX 0.8 /* x-center, de Bruijn diagram */
# define JY 0.5 /* y-center, de Bruijn diagram */
# define RI 0.455 /* inner radius, de Bruijn diagram */
# define RO 0.475 /* outer radius, de Bruijn diagram */
# define NW 24 /* pause after so many lines */
int dd; /* # points in de Bruijn ring */
int mc, nc, nl; /* column & line control */
/* edit the de Bruijn diagram */
edijn() {char c;
clijn();
dd=KK*KK;
ijn(dd,KK,2);
while (0<1) {
videocursor(0,0,36);
videoputc('?',2);
c=kbdin();
if (c=='\015') break;
videocursor(0,0,38);
videoputc(c,2);
videocursor(0,0,36);
videoputc(' ',2);
videoscroll(1,0,24,14,0,0);
videocursor(0,0,0);
kwait(3);
switch (c) {
case 'A': dd=KK*KK; ijn(dd,KK,2); sijn(dd,0,1); break;
case 'B': dd=KK*KK; ijn(dd,KK,2); sijn(dd,1,1); break;
case 'C': dd=KK*KK; ijn(dd,KK,2); sijn(dd,2,1); break;
case 'D': dd=KK*KK; ijn(dd,KK,2); zijn(dd,0,1); break;
case 'E': dd=KK*KK; ijn(dd,KK,2); zijn(dd,1,1); break;
case 'F': dd=KK*KK; ijn(dd,KK,2); zijn(dd,2,1); break;
case 'G': kwait(0); printf("Precursors 0*:"); kwait(0); xpass1(0); break;
case 'H': kwait(0); printf("Precursors 1*:"); kwait(0); xpass1(1); break;
case 'I': kwait(0); printf("Precursors 2*:"); kwait(0); xpass1(2); break;
case 'a': kwait(0); printf("(1,1) gliders:"); kwait(0); apass1(2); break;
case 'b': kwait(0); printf("(1,0) static:"); kwait(0); apass1(1); break;
case 'c': kwait(0); printf("(1,-1) gliders:"); kwait(0); apass1(0); break;
case 'd': kwait(0); printf("(2,-2) gliders:"); kwait(0); bpass1(0); break;
case 'e': kwait(0); printf("(2,-1) gliders:"); kwait(0); bpass1(1); break;
case 'f': kwait(0); printf("(2,0) cycles:"); kwait(0); bpass1(2); break;
case 'g': kwait(0); printf("(2,1) gliders:"); kwait(0); bpass1(3); break;
case 'h': kwait(0); printf("(2,2) gliders:"); kwait(0); bpass1(4); break;
case 'i': kwait(0); printf("(3,-3) gliders:"); kwait(0); cpass1(0); break;
case 'j': kwait(0); printf("(3,-2) gliders:"); kwait(0); cpass1(1); break;
case 'k': kwait(0); printf("(3,-1) gliders:"); kwait(0); cpass1(2); break;
case 'l': kwait(0); printf("(3,0) cycles:"); kwait(0); cpass1(3); break;
case 'm': kwait(0); printf("(3,1) gliders:"); kwait(0); cpass1(4); break;
case 'n': kwait(0); printf("(3,2) gliders:"); kwait(0); cpass1(5); break;
case 'o': kwait(0); printf("(3,3) gliders:"); kwait(0); cpass1(6); break;
case 'p': kwait(0); printf("(4,-4) gliders:"); kwait(0); dpass1(0); break;
case 'q': kwait(0); printf("(4,-3) gliders:"); kwait(0); dpass1(1); break;
case 'r': kwait(0); printf("(4,-2) gliders:"); kwait(0); dpass1(2); break;
case 's': kwait(0); printf("(4,-1) gliders:"); kwait(0); dpass1(3); break;
case 't': kwait(0); printf("(4,0) cycles:"); kwait(0); dpass1(4); break;
case 'u': kwait(0); printf("(4,1) gliders:"); kwait(0); dpass1(5); break;
case 'v': kwait(0); printf("(4,2) gliders:"); kwait(0); dpass1(6); break;
case 'w': kwait(0); printf("(4,3) gliders:"); kwait(0); dpass1(7); break;
case 'x': kwait(0); printf("(4,4) gliders:"); kwait(0); dpass1(8); break;
case '1': dd=KK*KK; clijn(); ijn(dd,KK,2); break;
case '2': dd=KK*KK*KK; clijn(); ijn(dd,KK,2); break;
case '3': dd=KK*KK*KK*KK; clijn(); ijn(dd,KK,2); break;
case '4': dd=KK*KK*KK*KK*KK; clijn(); ijn(dd,KK,2); break;
case '5': dd=KK*KK*KK*KK*KK*KK; clijn(); ijn(dd,KK,2); break;
case '6': dd=KK*KK*KK*KK*KK*KK*KK; clijn(); ijn(dd,KK,2); break;
case '+': videopalette(WHCYMAG); break;
case '-': videopalette(YELREGR); break;
case '?': case '/': clijn(); break;
default: break;
}; /* end switch */
}; /* end while */
videopalette(WHCYMAG);
videomode(T80X25);
}
/* clear edijn screen and set up menu */
clijn() {
videomode(COLGRAF);
videopalette(YELREGR);
videocursor(0,0,0);
scrrul();
videocursor(0,3,0);
printf("de Bruijn ring\n\n");
printf("abc - (1,x)\n");
printf("ABC - (all)\n");
printf("defgh - (2,x)\n");
printf("ijklmno (3,x)\n");
printf("pqrstuvwx (4)\n");
printf("123456 -diagram\n");
printf("DEF - 0*1*2*\n");
printf("GHI - full n*\n");
printf("+- - pallette\n");
printf("z - clr screen\n");
printf("<cr> - exit\n\n");
}
/* generate a de Bruijn diagram with m nodes, n links per node, color l */
ijn(m,n,l) int m, n, l; {
int i, j;
double ii, jj, nn, x, y, t, h;
double sin(), cos();
nn=(double)(n);
t=6.28318/((double)(m));
h=0.5*t;
for (i=0; i<m; i++) {
ii=(double)(i);
for (j=0; j<n; j++) {
jj=(double)(j);
x=JX-RI*sin(ii*t+h);
y=JY-RI*cos(ii*t+h);
videoline(x,y,0);
x=JX-RO*sin((nn*ii+jj)*t+h);
y=JY-RO*cos((nn*ii+jj)*t+h);
videoline(x,y,l);
};
};
}
/* insert a link into a de Bruijn diagram */
/* m - number of vertices */
/* u - initial vertex */
/* v - terminal vertex */
/* l - color of link */
lijnk(m,u,v,l) int m, u, v, l; {
double uu, vv, x, y, t, h;
double sin(), cos();
t=6.28318/((double)(m));
uu=t*((double)(u));
vv=t*((double)(v));
h=0.5*t;
x=JX-RI*sin(uu+h);
y=JY-RI*cos(uu+h);
videoline(x,y,0);
x=JX-RO*sin(vv+h);
y=JY-RO*cos(vv+h);
videoline(x,y,l);
}
/* generate a de Bruijn diagram showing antecedents of state k in color l */
sijn(m,k,l) int m, k, l; {
int i0, i1, i2;
double th, x, y, t, h;
double sin(), cos();
t=6.28318/((double)(m));
h=0.5*t;
for (i0=0; i0<KK; i0++) {
for (i1=0; i1<KK; i1++) {
for (i2=0; i2<KK; i2++) {
if (k==ascrule[i0][i1][i2]-'0') {
th=((double)(i0*KK+i1))*t+h;
x=JX-RI*sin(th);
y=JY-RI*cos(th);
videoline(x,y,0);
th=((double)(i1*KK+i2))*t+h;
x=JX-RO*sin(th);
y=JY-RO*cos(th);
videoline(x,y,l);
}; /* end if */
};};}; /* end for's */
} /* end sijn */
/* generate a de Bruijn diagram showing the (1,k) links in color l */
zijn(m,k,l) int m, k, l; {
int i, i0, i1, i2;
double th, x, y, t, h;
double sin(), cos();
t=6.28318/((double)(m));
h=0.5*t;
for (i0=0; i0<KK; i0++) {
for (i1=0; i1<KK; i1++) {
for (i2=0; i2<KK; i2++) {
i=ascrule[i0][i1][i2]-'0';
if ((k==0 && i==i0) || (k==1 && i==i1) || (k==2 && i==i2)) {
th=((double)(i0*KK+i1))*t+h;
x=JX-RI*sin(th);
y=JY-RI*cos(th);
videoline(x,y,0);
th=((double)(i1*KK+i2))*t+h;
x=JX-RO*sin(th);
y=JY-RO*cos(th);
videoline(x,y,l);
}; /* end if */
};};}; /* end for's */
} /* end zijn */
/* plot graph on video screen */
/* move pen from present position to (x,y) */
/* raised if l=0; color l if l>0 */
videoline(x,y,l) double x, y; int l; {
int k, ax, ay, dx, dy, di, dj, x1, y1;
/* if (x<0.0) return; if (x>1.0) return */
/* if (y<0.0) return; if (y>1.0) return */
x1=(int)(199.0*(1.0-y));
y1=(int)(199.0*x);
dx=x1-ix0;
dy=y1-iy0;
ax=dx>=0?dx:-dx;
ay=dy>=0?dy:-dy;
di=dx>=0?1:-1; if (dx==0) di=0;
dj=dy>=0?1:-1; if (dy==0) dj=0;
if (l>0) {if (ax!=0 || ay!=0) {
if (ax>=ay) {for (k=0; k<=ax; k++) videodot(ix0+di*k,60+iy0+(k*dy)/ax,l);}
else {for (k=0; k<=ay; k++) videodot(ix0+(k*dx)/ay,60+iy0+dj*k,l);};
}; };
ix0=x1;
iy0=y1;
}
/* approximation to sine */
double sin(x) double x; {
if (x<0.0) return(-sin(-x));
while (x>=6.28318) x-=6.28318;
if (x>=3.142) return(-sin(x-3.14159));
if (x>=1.571) return(sin(3.14159-x));
return(x*(1.0-0.166*(x*x-0.05*x*x)));
}
/* approximation to cosine */
double cos(x) double x; {double sin(); return(sin(x+1.57079));}
/* ONE31.C */
/* Pass 1a analyzes all the configurations which fulfil (1,-1+l) */
apass1(l) {
char arry[KK][KK][KK];
int i,j,k,m;
mc=2;
asctobin();
printf(" Pass1a\015");
for (i